import 'package:flutter/material.dart';

class BorderTabIndicator extends Decoration {
  final double indicatorHeight;
  final double textScaleFactor;

  const BorderTabIndicator({required this.indicatorHeight, required this.textScaleFactor});

  @override
  _BorderPainter createBoxPainter([VoidCallback? onChanged]) =>
      _BorderPainter(this, indicatorHeight, textScaleFactor, onChanged);
}

class _BorderPainter extends BoxPainter {
  final BorderTabIndicator decoration;
  final double indicatorHeight;
  final double textScaleFactor;

  _BorderPainter(this.decoration, this.indicatorHeight, this.textScaleFactor,
      VoidCallback? onChanged);

  @override
  void paint(Canvas canvas, Offset offset, ImageConfiguration configuration) {
    assert(configuration != null);
    assert(configuration.size != null);
    final horizontalInset = 16 - 4 * textScaleFactor;
    final rect = Offset(offset.dx + horizontalInset,
            (configuration.size!.height / 2) - indicatorHeight / 2 - 1) &
        Size(configuration.size!.width - 2 * horizontalInset, indicatorHeight);
    final paint = Paint();
    paint.color = Colors.white;
    paint.style = PaintingStyle.stroke;
    paint.strokeWidth = 2;
    canvas.drawRRect(
      RRect.fromRectAndRadius(rect, const Radius.circular(56)),
      paint,
    );
  }
}
